import {createRouter,createWebHistory} from "vue-router";
import ResidentsList from "../pages/ResidentsList.vue";
import chatPage from "../pages/ChatPage.vue";
const routes=[
    {path:'/',redirect:'login'},
    {path:'/login',name:'login',component:()=>import("../pages/Login.vue")},
    {path: '/home',name:'home',component:()=>import("../layout/Home.vue"),
    children:[
        {path: 'workBench',name:'workBench',component:()=>import("../pages/WorkBench.vue")},
        {path: 'allRecord',component:()=>import("../pages/sign-manage/AllRecord.vue")},
        {path:'serviceRecord',name:'serviceRecord',component:()=>import("../pages/ServiceRecord.vue")},
        {path:'editServiceInfo/:id',name:'editServiceInfo',props:true,component:()=>import("../pages/EditServiceInfo.vue")},
        {path:'serviceWaitFinish',name: 'serviceWaitFinish',component:()=>import('../pages/ServiceWaitFinish.vue')},
        {path:'serviceInfo/:id',name:'serviceInfo',props:true,component:()=>import("../pages/ServiceInfo.vue")},
        {path:'serviceFinished',name:'serviceFinished',component:()=>import('../pages/ServiceFinished.vue')},
        {path:'serviceInfoDetail/:id',name:'serviceInfoDetail',props:true,component:()=>import("../pages/ServiceInfoDetail.vue")},
        {path: '/sysTeam',name: 'sysTeam',component:()=>import("../pages/SysTeam.vue")},
        {path: '/sysTeamDetail/:id',name: 'sysTeamDetail',props:true,component:()=>import("../pages/SysTeamDetail.vue")},
        {path: '/JoinTeam',name: 'JoinTeam',props:true,component:()=>import("../pages/JoinTeam.vue")},
        {path: '/AddTeam',name: 'AddTeam',props:true,component:()=>import("../pages/AddTeam.vue")},
        {path: 'residentsList',component:ResidentsList},
        {path:'chatPage',component:chatPage},
    ]},
]
const router=createRouter({
    history:createWebHistory(),
    routes
})

router.beforeEach((to,from,next)=>{
    //设置白名单
    const whiteList=['/login']
    const token=sessionStorage.getItem('token')
    if (token){
        next()
    }else {
        if (whiteList.includes(to.path)){
            next()
        }else {
            next('/login')
        }
    }
})
export default router